package com.kuang.dao.role;

import com.kuang.dao.BaseDao;
import com.kuang.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao{
    //获取角色列表
    public List<Role> getRoleList(Connection connection) throws SQLException {
       System.out.println("UserDaoImpl--->getRoleList");
        ArrayList<Role> roles = new ArrayList<Role>();
        PreparedStatement pstm = null;
        ResultSet rs = null;

        if (connection != null){
            String sql = "select * from smbms_role ";
            Object[] params = {};
//            System.out.println(params.length);
            rs = BaseDao.execute(connection,pstm,rs,sql,params);
            while (rs.next()){
                Role role = new Role();
                role.setId(rs.getInt("id"));
                role.setRoleCode(rs.getString("roleCode"));
                role.setRoleName(rs.getString("roleName"));
                role.setCreatedBy(rs.getInt("createdBy"));
                role.setModifyBy(rs.getInt("modifyBy"));
                role.setCreationDate(rs.getTimestamp("creationDate"));
                role.setModifyDate(rs.getTimestamp("modifyDate"));
                roles.add(role);
            }
            BaseDao.closeResource(null,pstm,rs);
        }
        return roles;
    }
}
